$(function() {
	$.ajax({
		url: "https://newapp.icandrive.cn/api/news.php",
		type: 'post',
		dataType: 'json',
		data: {},
		success: function(data) {

			$(data).each(function() {

				$('.swiper-wrapper').append('<div class="swiper-slide"  onclick="jump(' + "'" + this.content + "'" + ')"> ' +
					'<a class="carousel_link" ><img class="carousel_pic" src="https://newapp.icandrive.cn/tp/Uploads/' +
					this.img + '" alt="error"><div class="contents clearfix"><div class="news_1">' +
					'<h3 class="news_title clearfix">' + this.title + '</h3><article class="news_content clearfix"></article></div><div class="news_2"><h4 class="news_source clearfix">' + this.source + '' +
					'</h4><article class="news_time clearfix">' + this.create_time + '</article></div></div></a></div>');
			});

			var swiper = new Swiper('.swiper-container', {
				pagination: '.swiper-pagination',
				paginationClickable: true,
				parallax: true,
				speed: 300,

				loop: true,
				grabCursor: false,
				/*   resistanceRatio: 0，*/
				resistanceRatio: 0.9,
				observer: true,
				observeParents: true,
				autoplayDisableOnInteraction: false,
			});

		}
	});

	$(".nav_list_num1").click(function() {
		var token = localStorage.phone;
		$.ajax({
			url: "https://newapp.icandrive.cn/api/index.php",
			type: 'post',
			data: {
				token: token
			},
			dataType: 'json',
			success: function(data) {
				if(data.status == 200) {
					$.ajax({
						url: "https://newapp.icandrive.cn/api/realName.php",
						type: 'post',
						data: {
							token: token
						},
						dataType: 'json',
						success: function(data) {
							console.log(data);
							if(data.status == 200) {
								window.location.href = "../info/drive_information.html";
							}
							if(data.status == 250) {
								layer.msg("请重新登录");
								setInterval(function() {
									window.location.href = "../login/log_in.html";
								}, 2000)
							}
							if(data.status == 400) {
								layer.msg('请先实名认证');
								setInterval(function() {
									window.location.href = "../info/information.html"
								}, 2000)
							}
						},
						error: function() {
							layer.msg('系统繁忙', function() {
								history.go(0)
							}, 1000);
						}
					});

				}
				if(data.status == 400) {
					layer.msg('您已申请过免费试驾');
				}

			},
			error: function() {
				layer.msg('系统繁忙', function() {
					history.go(0)
				}, 1000);
			}
		});
	});
	$(".nav_list_num3").click(function() {
		var token = localStorage.phone;
		$.ajax({
			url: "https://newapp.icandrive.cn/api/realName.php",
			type: 'post',
			data: {
				token: token
			},
			dataType: 'json',
			success: function(data) {
				if(data.status == 200) {
					window.location.href = "../schoolList/schoolList.html";
				}
				if(data.status == 250) {
					layer.msg("请重新登录");
					setInterval(function() {
						window.location.href = "../login/log_in.html";
					}, 2000)
				}
				if(data.status == 400) {
					layer.msg('请先实名认证');
					setInterval(function() {
						window.location.href = "../info/information.html"
					}, 2000)
				}

			},
			error: function() {
				layer.msg('系统繁忙', function() {
					history.go(0)
				}, 1000);
			}
		});
	});

	$(".nav_list_num4").click(function() {
		var token = localStorage.phone;
		$.ajax({
			url: "https://newapp.icandrive.cn/api/realName.php",
			type: 'post',
			data: {
				token: token
			},
			dataType: 'json',
			success: function(data) {
				if(data.status == 200) {
					window.location.href = "../date_teacher/arrange_teaching.html";
				}
				if(data.status == 250) {
					layer.msg("请重新登录");
					setInterval(function() {
						window.location.href = "../login/log_in.html";
					}, 2000)
				}
				if(data.status == 400) {
					layer.msg('请先实名认证');
					setInterval(function() {
						window.location.href = "../info/information.html"
					}, 2000)
				}

			},
			error: function() {
				layer.msg('系统繁忙', function() {
					history.go(0)
				}, 1000);
			}
		});
	});

	/*搜索框内侧*/
	$(".search_one").click(function() {
		layer.msg("内测中");
	});



	/*热更新版本*/
	mui.init();
	var _config = {
		url: 'https://newapp.icandrive.cn/api/'
	}
	var checkUrl = _config.url + "edition.php";
	//需要传递当前的版本
	function checkUpdate(wgtVer) {

		//  plus.nativeUI.showWaiting("检测更新...");
		mui.ajax(checkUrl, {
			dataType: "json",
			type: 'POST',
			data: {
				ver: wgtVer
			},
			success: function(json) {
				plus.nativeUI.closeWaiting();
				if(parseInt(json.code) == 1) {
					//可以升级
					plus.nativeUI.confirm("检查到当前版本有最新更新，下载升级？",
						function(event) {
							if(event.index == 0) {

								downWgt(json.url); //下载更新版的地址
							}
						}, '系统消息', ['马上升级', '下次再说']);
				} else {
					//                                              plus.nativeUI.toast("无新版本可更新！");
				}
			},
			error: function(xhr, error) {
				plus.nativeUI.closeWaiting();
				//plus.nativeUI.toast('检测更新失败！');
			}
		});
	}
	// 下载wgt文件

	function downWgt(wgtUrl) {
		plus.nativeUI.showWaiting("下载更新文件...");
		plus.downloader.createDownload(wgtUrl, {
			filename: "_doc/update/"
		}, function(d, status) {
			if(status == 200) {
				//console.log("下载wgt成功："+d.filename);
				installWgt(d.filename); // 安装wgt包
			} else {
				//console.log("下载wgt失败！");
				plus.nativeUI.alert("下载更新失败！");
			}
			plus.nativeUI.closeWaiting();
		}).start();
	}
	// 更新应用资源
	function installWgt(path) {
		plus.nativeUI.showWaiting("安装更新文件...");
		plus.runtime.install(path, {}, function() {
			plus.nativeUI.closeWaiting();
			plus.nativeUI.alert("应用资源更新完成！", function() {
				plus.runtime.restart();
			});
		}, function(e) {
			plus.nativeUI.closeWaiting();
			plus.nativeUI.alert("安装更新文件失败[" + e.code + "]：" + e.message);
		});
	}

	//在页面中初始化plus插件
	mui.init();
	mui.plusReady(function() {
		plus.runtime.getProperty(plus.runtime.appid, function(inf) {

			checkUpdate(inf.version)

		});
	});
	//检测升级
	function upgrade_app_wgt() {
		plus.runtime.getProperty(plus.runtime.appid, function(inf) {
			checkUpdate(inf.version);
			console.log(inf.version)
			sessionStorage.setItem('upgrade', '1');
		});
	}

}); /*end $function()*/

//定义一个方法轮播图跳转
function jump(res) {
	localStorage.iframe_url = res;
	window.location.href = "jump.html";
}


/*动态获取html 字体大小*/
setFontSize(1080);


/*监听手机返回按键并且带确认按钮 引用public_js公共文件 public*/
confirm_return();
